<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="反馈标题" prop="feedbackTitle">
        <el-input
          v-model="queryParams.feedbackTitle"
          placeholder="请输入反馈标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否解决" prop="isSolve">
        <el-input
          v-model="queryParams.isSolve"
          placeholder="请输入是否解决"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="feedbackInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="反馈标题" align="center" prop="feedbackTitle" />
      <el-table-column label="反馈类型" align="center" prop="feedbackType" >
        <template v-slot="{ row }">
          <el-tag type="success">{{ row.feedbackType }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="反馈内容" align="center" prop="feedbackContent" />
      <el-table-column label="反馈人" align="center" prop="feedbackPeople" />
      <el-table-column label="是否解决" align="center" prop="isSolve" >
        <template v-slot="{ row }">
          <el-tag type="warning" v-show="row.isSolve == 0">未解决</el-tag>
          <el-tag type="success" v-show="row.isSolve == 1">已解决</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="notes" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改反馈信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="反馈标题" prop="feedbackTitle">
          <el-input v-model="form.feedbackTitle" placeholder="请输入反馈标题" />
        </el-form-item>
        <el-form-item label="反馈类型" prop="feedbackType">
          <el-select v-model="form.feedbackType" placeholder="请选择">
            <el-option
              v-for="item in feedbackTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
<!--          <el-input v-model="form.feedbackType" placeholder="请输入反馈类型" />-->
        </el-form-item>
        <el-form-item label="反馈内容">
          <el-input
            type="textarea"
            :rows="3"
            placeholder="请输入内容"
            v-model="form.feedbackContent">
          </el-input>
        </el-form-item>
        <el-form-item label="反馈人" prop="feedbackPeople">
          <el-input v-model="form.feedbackPeople" placeholder="请输入" />
        </el-form-item>
<!--        <el-form-item label="是否解决" prop="isSolve">-->
<!--          <el-select v-model="form.isSolve" placeholder="请选择">-->
<!--            <el-option-->
<!--              v-for="item in solveStatus"-->
<!--              :key="item.value"-->
<!--              :label="item.label"-->
<!--              :value="item.value">-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--          <el-input v-model="form.isSolve" placeholder="请输入是否解决" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="结果备注">-->
<!--          <el-input-->
<!--            type="textarea"-->
<!--            :rows="3"-->
<!--            placeholder="请输入内容"-->
<!--            v-model="form.notes">-->
<!--          </el-input>-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFeedbackInfo, getFeedbackInfo, delFeedbackInfo, addFeedbackInfo, updateFeedbackInfo } from "@/api/business/feedbackInfo";

export default {
  name: "FeedbackInfo",
  data() {
    return {
      solveStatus: [{
        value: '0',
        label: '未解决'
      }, {
        value: '1',
        label: '已解决'
      }],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 反馈信息表格数据
      feedbackInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        feedbackType: null,
        feedbackTitle: null,
        feedbackContent: null,
        feedbackPeople: null,
        isDelete: null,
        isSolve: null,
        createMemberId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      feedbackTypeList: [{
        value: '设施反馈',
        label: '设施反馈'
      }, {
        value: '服务反馈',
        label: '服务反馈'
      }, {
        value: '安全反馈',
        label: '安全反馈'
      }, {
        value: '环境卫生反馈',
        label: '环境卫生反馈'
      }, {
        value: '管理反馈',
        label: '管理反馈'
      },{
        value: '其他反馈',
        label: '其他反馈'
      }],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询反馈信息列表 */
    getList() {
      this.loading = true;
      listFeedbackInfo(this.queryParams).then(response => {
        this.feedbackInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        feedbackId: null,
        feedbackType: null,
        feedbackTitle: null,
        feedbackContent: null,
        feedbackPeople: null,
        isDelete: null,
        isSolve: null,
        createMemberId: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.feedbackId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加反馈信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const feedbackId = row.feedbackId || this.ids
      getFeedbackInfo(feedbackId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改反馈信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.feedbackId != null) {
            updateFeedbackInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFeedbackInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const feedbackIds = row.feedbackId || this.ids;
      this.$modal.confirm('是否确认删除反馈信息编号为"' + feedbackIds + '"的数据项？').then(function() {
        return delFeedbackInfo(feedbackIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/feedbackInfo/export', {
        ...this.queryParams
      }, `feedbackInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
